﻿using System;

namespace Freedom.Common
{
    /// <summary>
    /// AcronymAttribute
    /// </summary>
    [AttributeUsage(AttributeTargets.All)]
    public class AcronymAttribute : Attribute
    {
  
        /// <summary>
        /// Default
        /// </summary>
        public static readonly AcronymAttribute Default = new AcronymAttribute();

        // Methods
        /// <summary>
        /// Initializes a new instance of the <see cref="AcronymAttribute"/> class.
        /// </summary>
        public AcronymAttribute()
            : this(string.Empty)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="AcronymAttribute"/> class.
        /// </summary>
        /// <param name="acronym">The description.</param>
        public AcronymAttribute(string acronym)
        {
            AcronymValue = acronym;
        }

        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        /// 	<c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return true;
            }
            var attribute = obj as AcronymAttribute;
            return ((attribute != null) && (attribute.Acronym == Acronym));
        }

        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
        /// </returns>
        public override int GetHashCode()
        {
            return Acronym.GetHashCode();
        }

        /// <summary>
        /// When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.
        /// </summary>
        /// <returns>
        /// true if this instance is the default attribute for the class; otherwise, false.
        /// </returns>
        public override bool IsDefaultAttribute()
        {
            return Equals(Default);
        }

        // Properties
        /// <summary>
        /// Gets the acronym.
        /// </summary>
        /// <value>The acronym.</value>
        public virtual string Acronym
        {
            get
            {
                return AcronymValue;
            }
        }

        /// <summary>
        /// Gets or sets the acronym value.
        /// </summary>
        /// <value>The acronym value.</value>
        protected string AcronymValue { get; set; }
    }

 

}
